package net.hmr_radio.hmrbot.controller;

import net.hmr_radio.hmrbot.model.UserInfo;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import twitter4j.Twitter;

public abstract class BaseController extends Controller {

    protected Log log = LogFactory.getLog(getClass());

    protected UserInfo getLoginUser() {
        return sessionScope("loginUser");
    }

    protected Twitter getTwitter() {
        return sessionScope("twitter");
    }

    @Override
    protected Navigation forward(String path) {
        requestScope("loginUser", getLoginUser());
        return super.forward(path);
    }

    @Override
    protected Navigation handleError(Throwable error) throws Throwable {
        log.error("error", error);
        return redirect("/error");
    }
}
